<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/


namespace Member\Model;
use Think\Model;

class MemberTaskModel extends Model {
	
	public function SendNotice($params=array()){
		
		if($params['uid'] && $params['subject']){
			$params['dateline']=NowTime();
			$params['new']=1;
			if ($this->token(false)->create($params)){
				if($this->token(false)->add()){
					$this->UpdateData(intval($params['uid']));
					return true;
				}
			}
		}
	}
	
	public function UpdateData($uid=0){
		$newnum=$this->token(false)->where(" uid=$uid AND new=1 ")->count();
		M('Member')->token(false)->where(" uid=$uid ")->save(array('noticeread'=>$newnum));
	}
	
	public function ListData(){
		$pagenum=intval($_GET['p']);
		$wheresql=" uid=$this->uid ";
		$list=$this->token(false)->where($wheresql)->order('dateline DESC')->page($pagenum,10)->select();

		//页码-------------------------------
		$count=$this->token(false)->where($wheresql)->count();
		$Page = new \Think\Page($count,10);
		
		return array('list'=>$list,'page'=>$Page->show());
	}
	
	public function ShowData(){
		$id=intval($_GET['id']);
		$wheresql=" id=$id AND uid=$this->uid ";
		if($this->token(false)->where($wheresql)->count()){
			$this->where($wheresql)->save(array('new'=>0));
			$this->UpdateData(intval($this->uid));
			return $this->token(false)->where($wheresql)->find();
		}
		$this->error='数据不在！';
		return false;
	}
	
	function DeleteData($uid=0){
		$ids=ExplodeStrArr($_POST['id']);
		if($ids){
			if(!$uid){
				$uid=$this->uid;
			}
			$this->token(false)->where(" id IN($ids) AND uid=$uid ")->delete();
			$this->UpdateData(intval($uid));
			return true;
		}
		$this->error='请选择ID操作！';
		return false;
	}
	
	function SetReadData($uid=0){
		$ids=ExplodeStrArr($_POST['id']);
		if($ids){
			if(!$uid){
				$uid=$this->uid;
			}
			$this->token(false)->where(" id IN($ids) AND uid=$uid ")->save(array('new'=>0));
			$this->UpdateData(intval($uid));
			return true;
		}
		$this->error='请选择ID操作！';
		return false;
	}
}

?>